package com.yitong.xjd.services;

import java.text.DecimalFormat;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yitong.xjd.dao.GongJiJinDaiDao;
import com.yitong.xjd.domain.RequestDataGjj;
import com.yitong.xjd.domain.ReturnData4Gjj;

@Service
@Transactional(value = "secondTxManager", rollbackFor = Exception.class)
public class GongJiJinDaiServiceImpl implements GongJiJinDaiService{
	
	@Autowired
	private GongJiJinDaiDao gongJiJinDaiDao;
	
	//公积金贷款
	@Override
	public ReturnData4Gjj queryGjjed(RequestDataGjj o) {
		ReturnData4Gjj result=null;
		if(o.getCustno()==null||o.getGjjbase()==null){
			result=new ReturnData4Gjj("","0","报文缺失重要字段","0");
		}else{
			//获取客户信息
			String mergeCustId=gongJiJinDaiDao.getMergeId(o.getCustno());
			
			//计算公积金贷款
			if(mergeCustId!=null){
				try{
					String gjjbasestr=o.getGjjbase();
					double gjjbase=Double.parseDouble(gjjbasestr)*12;
					String str=new DecimalFormat("0").format(gjjbase);
					String dateStr=gongJiJinDaiDao.getNowTime("yyyy-MM-dd");
					System.out.println(dateStr);
					result=new ReturnData4Gjj(o.getCustno(),"1","计算成功",str,dateStr);
				}catch(Exception e){
					result=new ReturnData4Gjj(o.getCustno(),"0","计算过程异常","0");
				}
			}else{
				result=new ReturnData4Gjj(o.getCustno(),"0","客户不存在","0");
			}
		}
		return result;
	}

}
